<template>
    <div>
        <we-nav-bar></we-nav-bar>
        <div style="margin-bottom: 150px">
            <van-row>
                <van-col span="24">
                    <div style="margin-left: 1rem">
                        <p>当前 : {{now.name}}</p>
                    </div>
                </van-col>
            </van-row>
            <van-cell v-for="(item,index) of riqilist_val" @click="tiao_click(item.SickID,item.RecDate,item.SubHospitalID)" :title="item.RecDate"  :key="index"/>
            <van-row>
                <van-col>
                    <van-action-sheet v-model="show" :actions="users" @select="onSelect" />
                </van-col>
            </van-row>
        </div>
        <div class="btn-block" style="background: white;margin: 0;width: 100%;padding-top: 8px;text-align: center">
            <van-row>
                <van-col span="22" offset="1">
                    <van-button  type="info" @click="selectUser" style="border-radius: 0.2rem;overflow: hidden" size="large">切换就诊人</van-button>
                </van-col>
            </van-row>
        </div>
    </div>
</template>

<script>
    export default {
        name: "riqinglist",
        data(){
            return{
                url:'/app/wechat/Zjzf/',
                riqilist_val:[],
                show:false,
                users:[],
                now:{
                    name:'',
                    id_code:'',
                },
            }
        },
        created(){
            this.getUsers();
            this.currentMan();
        },
        methods:{
            //当前患者
            currentMan(){
                if(window.localStorage.getItem("current_patient_name") && window.localStorage.getItem("current_patient_ID")){
                    this.now.name = window.localStorage.getItem("current_patient_name");
                    this.now.id_code = window.localStorage.getItem("current_patient_ID");
                    this.riqilist_func(this.now.id_code);
                }else{
                    this.getLoginUser();
                }
            },
            //获取用户列表
            getUsers(){
                this.axios.post('/app/wechat/record/huanzhe/mid/2.html').then(({data}) => {
                    if(data.error===0){
                        this.users = data.info
                    }
                })
            },
            //点击按钮
            selectUser(){
                this.show = !this.show;
            },
            //获取日清单列表
            riqilist_func(id_code){

                this.http.post("/app/wechat/Wujiacha/riqinglist/mid/2", {'sfz': id_code}).then(res=>{
                    if (res.data.error==0){
                        this.riqilist_val=res.data.info

                    }else{
                        this.$notify({ type: 'warning', message: res.data.msg });
                        this.riqilist_val=[]
                    }
                })
            },
            tiao_click(SickID,RecDate,SubHospitalID){
                this.$router.push({name:"riqingxiang",query:{SickID:SickID,RecDate:RecDate,SubHospitalID:SubHospitalID}})
            },
            //获取当前登录人
            getLoginUser(){
                this.axios.post(this.url + 'loguser/mid/2.html').then(({data}) => {
                    if(data.code===0){
                        this.now = data.data
                        this.riqilist_func(this.now.id_code);
                    }
                })
            },
            //选择用户
            onSelect(item){
                this.now.name = item.name;
                this.now.id_code = item.id_code;
                window.localStorage.setItem("current_patient_name",item.name)
                window.localStorage.setItem("current_patient_ID",item.id_code)
                this.riqilist_func(this.now.id_code);
                this.show = false;
            },
        }
    }
</script>

<style scoped>
    .btn-block{
        position: fixed;
        bottom: 5px;
    }
</style>
